#include "confReader.hpp"
#include <nlohmann/json.hpp>
#include <fstream>
#include <stdexcept>

confReader::confReader()
{
  std::ifstream f("CameraConfig");
  if(!f.is_open())
    throw std::runtime_error("无法打开配置文件");
  nlohmann::json conf=nlohmann::json::parse(f);
  if(!conf["Server_Port"].is_number() || !conf["Camera"].is_array())
    throw std::runtime_error("JSON文件格式错误");
  ServerPort=conf["Server_Port"];
  nlohmann::json clist=conf["Camera"];
  for(auto i : clist)
    if(i.is_string())
      cameraList.push_back(i);
}

int confReader::GetServerPort()
{
  return ServerPort;
}

std::vector<std::string> & confReader::GetCameraList()
{
  return cameraList;
} 
